import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int[] a = new int[n];
        for(int i = 0; i < n; i++) {
            a[i]=in.nextInt();
        }

        int begin = 0, end = n - 1, sum = 0;
        int tempSum = 0, tempBegin = 0, tempEnd = 0;

        for(int i = 0; i < n; i++) {
            if(tempSum >= 0) {
                tempSum += a[i];
                tempEnd = i;
            } else {
                tempSum = 0;
                tempSum += a[i];
                tempBegin = i;
                tempEnd = i;
            }
            if(tempSum > sum || (tempSum == 0 && end == n - 1)) {
                sum = tempSum;
                begin = tempBegin;
                end = tempEnd;
            }
        }
        System.out.println(sum + " " + a[begin] + " " + a[end]);
    }
}
